<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /**
         * slice截取元素
         * 操作首尾元素：push | pop | unshift | shift
         * 操作中间元素：splice 返回截取的数组
         */
        const arr = Array.prototype.slice.call([1, 2, 3], 0)
        console.log(arr); // [1, 2, 3]

        const re = arr.splice(1, 0, 5, 6) 
        console.log(re); // []
        console.log(arr); // [1, 5, 6, 2, 3]
        const re2 = arr.splice(1, 1)
        console.log(re2, arr); // [5] [1, 6, 2, 3]

        function move(arr, from, to) {
            const res = [...arr]
            const item = res.splice(from - 1, 1)
            res.splice(to - 1, 0, ...item)
            return res
        }
        console.log(move([1, 2, 3, 4, 5, 6, 7], 2, 5)); // [1, 3, 4, 5, 2, 6, 7]
        console.log(move([1, 2, 3, 4, 5, 6, 7], 5, 2)); // [1, 5, 2, 3, 4, 6, 7]
    </script>
</body>
</html>